package com.hxexp.weixin.test;

import static org.junit.Assert.assertTrue;

import java.util.Random;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.MethodSorters;

import com.qq.weixin.constant.CompiledPattern;

/**
 * @author li.jiang
 *
 */
@RunWith(BlockJUnit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class XMLMatcheTester {
    @Test
    public void testCase01() {
        String xml = " <xml>\n" +
                "<ToUserName><![CDATA[gh_ac216ed6e766]]></ToUserName>\n" +
                "<FromUserName><![CDATA[o5GuMs3VA_8xB6VCNKaTdFQHVQ_U]]></FromUserName>\n" +
                " <CreateTime>1428562454</CreateTime> \n" +
                "<MsgType><![CDATA[event]]></MsgType>\n" +
                "<Event><![CDATA[CLICK]]></Event>\n" +
                "<EventKey><![CDATA[h]]></EventKey>\n" +
                "</xml>  ";
//        boolean b = Pattern.matches(MsgType.Regex.TEXT, xml);
//        String regex = "\\s*\\<xml\\>\\s*" +
//                       "\\s*\\<ToUserName\\>\\<\\!\\[CDATA\\[.+\\]\\]\\>\\<\\/ToUserName\\>\\s*" +
//                       "\\s*\\<FromUserName\\>\\<\\!\\[CDATA\\[.+\\]\\]\\>\\<\\/FromUserName\\>\\s*" +
//                       "\\s*\\<CreateTime\\>\\d+\\<\\/CreateTime\\>\\s*" +
//                       "\\s*\\<MsgType\\>\\<\\!\\[CDATA\\[text\\]\\]\\>\\<\\/MsgType\\>\\s*" +
//                       "\\s*\\<Content\\>\\<\\!\\[CDATA\\[.+\\]\\]\\>\\<\\/Content\\>\\s*" +
//                       "\\s*\\<MsgId\\>\\d+\\<\\/MsgId\\>\\s*" +
//                       "\\s*\\<\\/xml\\>\\s*";


//        Pattern p = Pattern.compile(regex, Pattern.DOTALL);
//        boolean b = p.matcher(xml).matches();
        boolean b = CompiledPattern.EVENT_CLICK.matcher(xml).matches();
        assertTrue(b);
    }
    @Test
    public void testCase02() {
        Random random = new Random(System.nanoTime());
        System.out.println("随机数：" + String.valueOf(random.nextLong()));
    }
}
